#include "Ladder.h"
#include "Resources.h"
#include "CollisionTypes.h"

Ladder::Ladder(const sf::Vector2f& position, const std::string& lhs, const std::string& rhs, unsigned short length)
{
	_component |= COMPONENT_DRAWABLE;
	_component |= COMPONENT_COLLIDEABLE;

	_ct.push_back(CT_LADDER);
	_mf.push_back(CT_PLAYER);
	_mf.push_back(CT_LADDER_CHECK);
	_killMe = false;
	_type = "Ladder";
	Resources::getSingletonPtr()->loadSprite(_sprite, lhs);
	Resources::getSingletonPtr()->loadSprite(_ladder, rhs);
	_position = position;
	_dimension.x = 28.0f;
	_dimension.y = 16.0f * static_cast<float>(length);
	_length = length;
	_sprite.setPosition(position);
	removeFlag(GRAVITY_AFFECTED);
}


Ladder::~Ladder(void)
{

}

void Ladder::move()
{

}

void Ladder::update()
{

}

void Ladder::draw(RenderManager* renderManager)
{
	float inc = _dimension.y / static_cast<float>(_length);
	float pos = inc;
	renderManager->draw(_sprite);
	for (unsigned short i = 1; i < _length; i++)
	{	
		_ladder.setPosition(_position.x, _position.y + pos);
		renderManager->draw(_ladder);
		pos += inc;
	}

	//For debug purpose
	/*sf::RectangleShape rec(sf::Vector2f(_dimension.x, _dimension.y));
	rec.setPosition(collisionBox().left, collisionBox().top);
	renderManager->draw(rec);*/
	
}

void Ladder::initialize()
{

}

void Ladder::clean()
{

}

sf::FloatRect Ladder::collisionBox(int type)
{
	return sf::FloatRect(_position.x - (_dimension.x * 0.5f), _position.y - 8.0f, _dimension.x, _dimension.y);
}
